#include "aky_program/aky_com_include.h"
typedef struct 
{
    e_aky_voice_t index;
    char * p_dr_str;
}s_voice_table_t;


#if 00
const s_voice_table_t voice_table[VOICE_MAX] = 
{
    {START_UP,"S:sd:voice/START_UP.wav"},
    {MEASURE_BEGIN,"S:sd:voice/MEASURE_BEGIN.wav"},
    {WAKE_IAM,"S:sd:voice/WAKE_IAM.wav"},
    {MEASURE_COMPLET,"S:sd:voice/MEASURE_COMPLET.wav"},
    {ACCORD_WHO_STAND,"S:sd:voice/ACCORD_WHO_STAND.wav"},
    {NORMAL,"S:sd:voice/NORMAL.wav"},
    {ON_LOW_SIDE,"S:sd:voice/ON_LOW_SIDE.wav"},
    {ON_HIGH_SIDE,"S:sd:voice/ON_HIGH_SIDE.wav"},

    {LEFT_SIDE,"S:sd:voice/LEFT_SIDE.wav"},
    {RIGHT_SIDE,"S:sd:voice/RIGHT_SIDE.wav"},

    {UNIT_SYS,"S:sd:voice/UNIT_SYS.wav"},
    {UNIT_DIA,"S:sd:voice/UNIT_DIA.wav"},
    {PULSE,"S:sd:voice/PULSE.wav"},
    {ZERO,"S:sd:voice/ZERO.wav"},
    {ONE,"S:sd:voice/ONE.wav"},
    {TWO,"S:sd:voice/TWO.wav"},
    {THREE,"S:sd:voice/THREE.wav"},
    {FOUR,"S:sd:voice/FOUR.wav"},
    {FIVE,"S:sd:voice/FIVE.wav"},
    {SIX,"S:sd:voice/SIX.wav"},
    {SEVEN,"S:sd:voice/SEVEN.wav"},
    {EIGHT,"S:sd:voice/EIGHT.wav"},
    {NINE,"S:sd:voice/NINE.wav"},
    {TEN,"S:sd:voice/TEN.wav"},
    {HUNDRED,"S:sd:voice/HUNDRED.wav"},
    {VOICE_CMD_POINT,"S:sd:voice/VOICE_CMD_POINT.wav"},
    {TIME,"S:sd:voice/TIME.wav"},
    {MMHG,"S:sd:voice/MMHG.wav"},
    {KPA,"S:sd:voice/KPA.wav"},
    {VIOCE_LOW_BAT,"S:sd:voice/VIOCE_LOW_BAT.wav"},
    {PLS_REMEASURE_OR_MEDICAL_ATTENT,"S:sd:voice/PLS_REMEASURE_OR_MEDICAL_ATTENT.wav"},
    {PREADAP_START,"S:sd:voice/PREADAP_START.wav"},
    {PREADAP_END,"S:sd:voice/PREADAP_END.wav"},
    {VOICE_RETEST_BP,"S:sd:voice/VOICE_RETEST_BP.wav"},
    {DATA_SENDING,"S:sd:voice/DATA_SENDING.wav"},
    {DATA_SEND_SUCC,"S:sd:voice/DATA_SEND_SUCC.wav"},
    {DATA_SEND_ERR,"S:sd:voice/DATA_SEND_ERR.wav"},
    {TRAIN_GREAT,"S:sd:voice/TRAIN_GREAT.wav"},
    {TRAIN_GOOD,"S:sd:voice/TRAIN_GOOD.wav"},
    {TRAIN_AVERAGE,"S:sd:voice/TRAIN_AVERAGE.wav"},
    {BP_HIGH_SEEK_MEDICAL_ATTENTION_FAST,"S:sd:voice/BP_HIGH_SEEK_MEDICAL_ATTENTION_FAST.wav"},
    
    {BG_1,"S:sd:bg_voice/BG_1.wav"},
    {BG_2,"S:sd:bg_voice/BG_2.wav"},
    {BG_3,"S:sd:bg_voice/BG_3.wav"},
};
#else
const s_voice_table_t voice_table[VOICE_MAX] = 
{
    {START_UP,"S:spi:voice/START_UP.wav"},
    {MEASURE_BEGIN,"S:spi:voice/MEASURE_BEGIN.wav"},
    {WAKE_IAM,"S:spi:voice/WAKE_IAM.wav"},
    {MEASURE_COMPLET,"S:spi:voice/MEASURE_COMPLET.wav"},
    {ACCORD_WHO_STAND,"S:spi:voice/ACCORD_WHO_STAND.wav"},
    {NORMAL,"S:spi:voice/NORMAL.wav"},
    {ON_LOW_SIDE,"S:spi:voice/ON_LOW_SIDE.wav"},
    {ON_HIGH_SIDE,"S:spi:voice/ON_HIGH_SIDE.wav"},

    {LEFT_SIDE,"S:spi:voice/LEFT_SIDE.wav"},
    {RIGHT_SIDE,"S:spi:voice/RIGHT_SIDE.wav"},

    {UNIT_SYS,"S:spi:voice/UNIT_SYS.wav"},
    {UNIT_DIA,"S:spi:voice/UNIT_DIA.wav"},
    {PULSE,"S:spi:voice/PULSE.wav"},
    {ZERO,"S:spi:voice/ZERO.wav"},
    {ONE,"S:spi:voice/ONE.wav"},
    {TWO,"S:spi:voice/TWO.wav"},
    {THREE,"S:spi:voice/THREE.wav"},
    {FOUR,"S:spi:voice/FOUR.wav"},
    {FIVE,"S:spi:voice/FIVE.wav"},
    {SIX,"S:spi:voice/SIX.wav"},
    {SEVEN,"S:spi:voice/SEVEN.wav"},
    {EIGHT,"S:spi:voice/EIGHT.wav"},
    {NINE,"S:spi:voice/NINE.wav"},
    {TEN,"S:spi:voice/TEN.wav"},
    {HUNDRED,"S:spi:voice/HUNDRED.wav"},
    {VOICE_CMD_POINT,"S:spi:voice/VOICE_CMD_POINT.wav"},
    {TIME,"S:spi:voice/TIME.wav"},
    {MMHG,"S:spi:voice/MMHG.wav"},
    {KPA,"S:spi:voice/KPA.wav"},
    {VIOCE_LOW_BAT,"S:spi:voice/VIOCE_LOW_BAT.wav"},
    {PLS_REMEASURE_OR_MEDICAL_ATTENT,"S:spi:voice/PLS_REMEASURE_OR_MEDICAL_ATTENT.wav"},
    {PREADAP_START,"S:spi:voice/PREADAP_START.wav"},
    {PREADAP_END,"S:spi:voice/PREADAP_END.wav"},
    {VOICE_RETEST_BP,"S:spi:voice/VOICE_RETEST_BP.wav"},
    {DATA_SENDING,"S:spi:voice/DATA_SENDING.wav"},
    {DATA_SEND_SUCC,"S:spi:voice/DATA_SEND_SUCC.wav"},
    {DATA_SEND_ERR,"S:spi:voice/DATA_SEND_ERR.wav"},
    {TRAIN_GREAT,"S:spi:voice/TRAIN_GREAT.wav"},
    {TRAIN_GOOD,"S:spi:voice/TRAIN_GOOD.wav"},
    {TRAIN_AVERAGE,"S:spi:voice/TRAIN_AVERAGE.wav"},
    {BP_HIGH_SEEK_MEDICAL_ATTENTION_FAST,"S:spi:voice/BP_HIGH_SEEK_MEDICAL_ATTENTION_FAST.wav"},
    
    {BG_1,"S:spi:bg_voice/BG_1.wav"},
    {BG_2,"S:spi:bg_voice/BG_2.wav"},
    {BG_3,"S:spi:bg_voice/BG_3.wav"},
};

#endif


static wav_obj_t* wav_1 = NULL;
uint8_t flag_wav_busy = 0;

stru_inner_voice_cmd_regist_t s_inner_voice_cmd;


s_voice_play_info_t s_voice_play_info = {0};
e_voice_play_stat_t e_voice_play_stat = VOICE_STAT_IDLE;
e_voice_play_stat_t e_voice_play_stat_last = VOICE_STAT_IDLE;
e_voice_play_stat_t e_voice_play_stat_last2 = VOICE_STAT_IDLE;
void my_dac_mute(void)
{
    DAC_PIN_OFF;
        __NOP();
}
void my_dac_open(void)
{
    DAC_PIN_ON;
        __NOP();
}

void voice_stop(void)
{
    my_dac_mute();
    if (wav_1 != NULL)
    {
        synwit_wav_close(wav_1);
        wav_1 = NULL;
    }
    flag_wav_busy = 0;
    e_voice_play_stat = VOICE_STAT_IDLE;
    e_voice_play_stat_last = VOICE_STAT_IDLE;
    e_voice_play_stat_last2 = VOICE_STAT_IDLE;
}

void stop_harware_dac(void)
{
	// DAC_Close(DAC);
    my_dac_mute();
}
uint8_t get_voice_level(uint16_t val)
{
    uint8_t res = 0;
    if (val <= 5)
    {
        res = 0;
    }    
    else if (val <= 20)
    {
        res = 1;
    }
    else if (val <= 40)
    {
        res = 2;
    }
    else if (val <= 60)
    {
        res = 3;
    }
    else if (val <= 80)
    {
        res = 4;
    }
    else
    {
        res = 5;
    }
		return res;
}

uint16_t get_video_voice_val(uint8_t level)
{
    uint8_t res = 0;
    if (level > 0)
    {
        if(level == VOICE_LEVEL_MAX)
        {
            res = 100;
        }
        else
        {
            res = VOICE_MIN_VAL_VIDEO + (level  * VOICE_LEVEL_STEP_VAL_VIDEO);
        }    
    }
    
	return res;
}


uint16_t index_data;
uint8_t flag_bg_done;

void aky_voice_table_play(e_aky_voice_t index)
{
    char *p_dr_str = NULL;
    if (index != WAKE_IAM && g_s_set.voice_level == 0)
    {
        flag_wav_busy = 0;
        return;
    }
    if (index >= VOICE_MAX)
    {
        return;
    }
    if (wav_1 != NULL)
    {
        synwit_wav_close(wav_1);
        wav_1 = NULL;
    }
    for (uint16_t i = 0; i < (sizeof(voice_table) / sizeof(voice_table[0])); i++)
    {
        if (index == voice_table[i].index)
        {
            p_dr_str = voice_table[i].p_dr_str;
            break;
        }

    }
    if (p_dr_str == NULL)
    {
        return;
    }
    wav_1 = synwit_wav_open(p_dr_str);
    if (wav_1 == NULL)
    {
        //打开语音文件失败
        return;
    }
    flag_wav_busy = 1;
    #if 00
    synwit_wav_play(wav_1,LV_TASK_PRIO_HIGHEST);

    #else
    synwit_wav_play(wav_1,LV_TASK_PRIO_HIGH);

    #endif
    if (index == WAKE_IAM)
    {
        synwit_wav_set_volume(wav_1, 100,WAV_VOLUME_ADJ_MODE_ABSOLUTE);
    }
    else
    {
        synwit_wav_set_volume(wav_1, g_s_set.voice_level * VOICE_LEVEL_STEP_VAL,WAV_VOLUME_ADJ_MODE_ABSOLUTE);
    }
    index_data = index;
    synwit_wav_set_on_completed_cb(wav_1,my_wav_completed_cb,&index_data);
}

void my_wav_completed_cb(wav_obj_t* wav_obj, void* user_data)
{
	// DAC_Close(DAC);
    uint16_t get_index;
    get_index = *(uint16_t*)user_data;
    if (wav_1 != NULL)
    {
        synwit_wav_close(wav_1);
        wav_1 = NULL;
    }
    flag_wav_busy = 0;
    if (get_index == BG_1 || get_index == BG_2 || get_index == BG_3)
    {
        flag_bg_done = 1;
    }
    
}


void voice_play_stat_pro(void)
{
    static uint16_t time_cnt = 0;
    static uint8_t step = 0;
    static uint32_t u32_tick_last = 0;
    static uint8_t bg_index = 0;

    uint8_t voice_temp = 0; // 取队列数据
    if (e_voice_play_stat_last2 != e_voice_play_stat)
    {
        e_voice_play_stat_last2 = e_voice_play_stat;
        time_cnt = 0;
        step = 0;
        u32_tick_last = 0;
        flag_bg_done = 0;
        bg_index = 0;
    }  

    switch (e_voice_play_stat)
    {
    case VOICE_STAT_IDLE:
    {
        if (step == 0)
        {
            step++;
            u32_tick_last = g_u32_tick_cnt;
        }
        else if (step == 1)
        {
            if (g_u32_tick_cnt - u32_tick_last > 5000 / 10)
            {
                u32_tick_last = g_u32_tick_cnt;
                stop_harware_dac();
                step++;
            }
        }
        
        e_voice_play_stat_last = VOICE_STAT_IDLE;
        if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_SINGLE)
        {
            aky_voice_table_play(s_voice_play_info.voice_index);
            clr_voice_play_info();
            e_voice_play_stat = VOICE_STAT_PLAY_SINGLE;
        }
        else if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_ARRAY)
        {
            clr_voice_play_info();
            e_voice_play_stat = VOICE_STAT_PLAY_ARRAY;
        }


        break;
    }
    // case VOICE_STAT_PLAY_BG:
    // {
    //     if (step == 0)
    //     {
    //         step++;
    //         dac_init(DAC_FORMAT_MSB12B);
    //         my_dac_open();
    //     }

    //     e_voice_play_stat_last = VOICE_STAT_PLAY_BG;
    //     if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_SINGLE)
    //     {
    //         aky_voice_table_play(s_voice_play_info.voice_index);
    //         clr_voice_play_info();
    //         e_voice_play_stat = VOICE_STAT_PLAY_SINGLE;
    //     }
    //     else if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_ARRAY)
    //     {
    //         clr_voice_play_info();
    //         e_voice_play_stat = VOICE_STAT_PLAY_ARRAY;
    //     }
    //     else
    //     {
    //         if (flag_wav_busy == 0)
    //         {
    //             if (g_u32_tick_cnt - u32_tick_last > 3000 / 10)
    //             {
    //                 u32_tick_last = g_u32_tick_cnt;
    //                 if (flag_wav_busy == 0)
    //                 {
    //                     if (flag_bg_done == 1)
    //                     {
    //                         flag_bg_done = 0;
    //                         bg_index++;
    //                         if (bg_index > 2)
    //                         {
    //                             bg_index = 0;
    //                         }
                            
    //                     }
    //                     // if (bg_index == 0)
    //                     // {
    //                     //     aky_voice_table_play(BG_1);
    //                     // }
    //                     // else if (bg_index == 1)
    //                     // {
    //                     //     aky_voice_table_play(BG_2);
    //                     // }
    //                     // else
    //                     // {
    //                     //     aky_voice_table_play(BG_3);
    //                     // }
    //                     aky_voice_table_play(BG_1);

    //                 }
    //             }
    //         }
    //         else
    //         {
    //             u32_tick_last = g_u32_tick_cnt;
    //         }
            
    //     }
        
    //     break;
    // }
    case VOICE_STAT_PLAY_SINGLE:
    {
        if (step == 0)
        {
            step++;
            dac_init(DAC_FORMAT_MSB12B);
            my_dac_open();
        }

        
        if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_SINGLE)
        {
            aky_voice_table_play(s_voice_play_info.voice_index);
            clr_voice_play_info();
            e_voice_play_stat = VOICE_STAT_PLAY_SINGLE;
        }
        
        if (flag_wav_busy == 0)
        {
            if (e_voice_play_stat_last == VOICE_STAT_IDLE)
            {
                e_voice_play_stat = VOICE_STAT_IDLE;
            }
            else if (e_voice_play_stat_last == VOICE_STAT_PLAY_BG)
            {
                e_voice_play_stat = VOICE_STAT_PLAY_BG;
            }
        }

        break;
    }    
    case VOICE_STAT_PLAY_ARRAY:
    {
        if (s_voice_play_info.e_voice_play_sub_info == INFO_PLAY_SINGLE)
        {
            aky_voice_table_play(s_voice_play_info.voice_index);
            clr_voice_play_info();
            e_voice_play_stat = VOICE_STAT_PLAY_SINGLE;
        }
        if (step == 0)
        {
            step++;
            dac_init(DAC_FORMAT_MSB12B);
            my_dac_open();
        }
        else if (step == 1)
        { 
            if (Queue_Count(&qVoice) > 0)
            {
                if (Queue_Pop(&qVoice, &voice_temp) == QUEUE_OK)
                {
                    aky_voice_table_play(voice_temp);
                    step=2;
                    // if (VoiceStop)
                    // {
                    //     Queue_Clear(&qVoice);
                    //     break;
                    // }
                    
                }
            }
            else
            {
                Queue_Clear(&qVoice);
                step = 20;
            }

        }
        else if (step == 2)
        {
            if (flag_wav_busy == 0)
            {
                step = 1;
                /* code */
            }

        }
        else if (step == 20)
        {
            if (e_voice_play_stat_last == VOICE_STAT_IDLE)
            {
                e_voice_play_stat = VOICE_STAT_IDLE;
            }
            else if (e_voice_play_stat_last == VOICE_STAT_PLAY_BG)
            {
                e_voice_play_stat = VOICE_STAT_PLAY_BG;
            }
        }

        
        break;
    }  
    default:
        break;
    }

}

void voice_play_single(e_aky_voice_t index)
{
    s_voice_play_info.e_voice_play_sub_info = INFO_PLAY_SINGLE;
    s_voice_play_info.voice_index = index;
}
void voice_play_array(void)
{
    s_voice_play_info.e_voice_play_sub_info = INFO_PLAY_ARRAY;
    s_voice_play_info.voice_index = 0;
}
void voice_enter_bg_play(void)
{
    if (e_voice_play_stat > VOICE_STAT_PLAY_BG)
    {
        e_voice_play_stat_last = VOICE_STAT_PLAY_BG;
    }
    else
    {
        e_voice_play_stat_last = VOICE_STAT_PLAY_BG;
        e_voice_play_stat = VOICE_STAT_PLAY_BG;
    }
}

void voice_exit_bg_play(void)
{
    if (e_voice_play_stat > VOICE_STAT_PLAY_BG)
    {
        e_voice_play_stat_last = VOICE_STAT_IDLE;
    }
    else if (e_voice_play_stat == VOICE_STAT_PLAY_BG)
    {
        e_voice_play_stat_last = VOICE_STAT_IDLE;
        e_voice_play_stat = VOICE_STAT_IDLE;
        my_dac_mute();
        if (wav_1 != NULL)
        {
            synwit_wav_close(wav_1);
            wav_1 = NULL;
        }
        flag_wav_busy = 0;
    }
    else
    {
        e_voice_play_stat_last = VOICE_STAT_IDLE;
    }
}

void clr_voice_play_info(void)
{
    memset(&s_voice_play_info,0,sizeof(s_voice_play_info_t));
}

void voice_init(void)
{
    Queue_Init(&qVoice, &voice_buffer[0], Q_VOICE_BUFFER_SIZE);
    s_inner_voice_cmd.inner_voice_cmd_number_offset = ZERO;
    s_inner_voice_cmd.inner_voice_cmd_ten = TEN;
    s_inner_voice_cmd.inner_voice_cmd_time = TIME;
    s_inner_voice_cmd.inner_voice_cmd_spot = VOICE_CMD_POINT;
    s_inner_voice_cmd.inner_voice_cmd_mm_hg = MMHG;
	 
	
    s_inner_voice_cmd.inner_voice_cmd_kilopascal = KPA;
    DAC_PIN_INIT;

}


// 语音处理分割数字百十个位
// inner_voice_cmd 注册的数字以及次数等指令偏移量, 用于适配不同语音列表
//  e_pres_unit 选择当前分割的数字类型 e_inner_voice_pres_unit_t 中定义
//  number 要进行分割的数字
void inner_voice_devide_number_pro(stru_inner_voice_cmd_regist_t inner_voice_cmd, e_inner_voice_pres_unit_t e_pres_unit, uint16_t number)
{
    uint8_t temp_hundred = 0;
    uint8_t temp_ten = 0;
    uint8_t temp_single = 0;
//    u8 temp_tenSingle = 0;
    temp_hundred = number / 100;
    temp_ten = number % 100 / 10;
    temp_single = number % 10;
	//temp_tenSingle = number%100;
	
	
    if (e_pres_unit == INNER_VOICE_PRES_UNIT_MMG || e_pres_unit == INNER_VOICE_PRES_UNIT_HEARTBEAT) // mmg和心跳次数处理
    {
        if (temp_hundred)
        {
            if(temp_hundred == 1)
			{
				Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_number_offset + 1); 
				Queue_Push(&qVoice, HUNDRED);                            // 入列				
			}

            else if(temp_hundred == 2)
			{
				Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_number_offset + 2); 
//				Queue_Push(&qVoice, hundred); // 入列				
				
				Queue_Push(&qVoice, HUNDRED);                            // 入列				
			}

			
			if(temp_ten ==0)
			{
				if(temp_single)  Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_number_offset);       // 入列
				
			}
//				
        }
		
		if (temp_ten)
		{
			temp_ten += inner_voice_cmd.inner_voice_cmd_number_offset;
			Queue_Push(&qVoice, temp_ten); 
			Queue_Push(&qVoice, TEN); // 入列                          // 入列
		}
		if (temp_single)
		{
			temp_single += inner_voice_cmd.inner_voice_cmd_number_offset;
			Queue_Push(&qVoice, temp_single); // 入列
		}

		if (e_pres_unit == INNER_VOICE_PRES_UNIT_HEARTBEAT && (!temp_hundred && !temp_ten && !temp_single)) // 心跳显示HI和LOW时传入的值为0, 此时播报"零次"
        {
            Queue_Push(&qVoice, 0 + inner_voice_cmd.inner_voice_cmd_number_offset); // 入列
        }

        if (e_pres_unit == INNER_VOICE_PRES_UNIT_MMG) // mmg和心跳次数处理
        {
            Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_mm_hg); // 入列
        }
        else if (e_pres_unit == INNER_VOICE_PRES_UNIT_HEARTBEAT) // mmg和心跳次数处理
        {
            Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_time); // 入列
        }
    }
    else // kpa处理
    {
		
        if (temp_hundred) // 实际上是十位 10倍数
        {
            if (temp_hundred == 1) // 为1时 只播报"十"
            {
                Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_ten); // 入列
            }
            else
            {
                temp_hundred += inner_voice_cmd.inner_voice_cmd_number_offset;
                Queue_Push(&qVoice, temp_hundred);                        // 入列
                Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_ten); // 入列
            }
        }
        if (temp_ten) // 实际上是个位 10倍数
        {
            temp_ten += inner_voice_cmd.inner_voice_cmd_number_offset;
            Queue_Push(&qVoice, temp_ten); // 入列
        }

        if (temp_single) // 实际上是小数位 10倍数
        {
            Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_spot); // 如果小数位有效 需要加一个"点"
            temp_single += inner_voice_cmd.inner_voice_cmd_number_offset;
            Queue_Push(&qVoice, temp_single); // 入列
        }
        Queue_Push(&qVoice, inner_voice_cmd.inner_voice_cmd_kilopascal); // 入列
		 
    }
	 
}



// 高压是+SYS+毫米汞柱/kpa+低压是+DIA+毫米汞柱/kpa+每分钟心跳次数是+PUL+次
// 组合语音处理函数
//  e_pres_unit 值:     e_inner_voice_pres_unit_t 中定义
//  sys 值:     血压高压 0~255 只需输入mmg \kpa由函数内部自动转换
//  dia 值:     血压低压 0~255
//  pul 值:     每分钟心跳 0~255
void inner_voice_combine_cmd(e_inner_voice_pres_unit_t e_pres_unit, uint8_t sys, uint8_t dia,uint8_t sys_right,uint8_t dia_right, uint8_t pul)
{
    uint16_t temp_sys = 0;
    uint16_t temp_dia = 0;
    temp_sys = sys;
    temp_dia = dia;
    if (e_pres_unit == INNER_VOICE_PRES_UNIT_KPA) // mmg -> kpa转换
    {
        temp_sys *= 4;
        temp_sys /= 3;
        temp_dia *= 4;
        temp_dia /= 3;
    }
	
 		Queue_Push(&qVoice, LEFT_SIDE); // 入列
		Queue_Push(&qVoice, UNIT_SYS); // 入列
		inner_voice_devide_number_pro(s_inner_voice_cmd, e_pres_unit, temp_sys);

		Queue_Push(&qVoice, UNIT_DIA); // 入列
		inner_voice_devide_number_pro(s_inner_voice_cmd, e_pres_unit, temp_dia);

        Queue_Push(&qVoice, RIGHT_SIDE);
        temp_sys = sys_right;
        temp_dia = dia_right;
        if (e_pres_unit == INNER_VOICE_PRES_UNIT_KPA) // mmg -> kpa转换
        {
            temp_sys *= 4;
            temp_sys /= 3;
            temp_dia *= 4;
            temp_dia /= 3;
        }
		Queue_Push(&qVoice, UNIT_SYS); // 入列
		inner_voice_devide_number_pro(s_inner_voice_cmd, e_pres_unit, temp_sys);

		Queue_Push(&qVoice, UNIT_DIA); // 入列
		inner_voice_devide_number_pro(s_inner_voice_cmd, e_pres_unit, temp_dia);


        // if(pul == 0) return;
		Queue_Push(&qVoice, PULSE); // 入列
		inner_voice_devide_number_pro(s_inner_voice_cmd, INNER_VOICE_PRES_UNIT_HEARTBEAT, pul);
	 

}

// 往语音队列中添加一个指令
void inner_voice_add_cmd(uint8_t e_voice_cmd)
{
    Queue_Push(&qVoice, e_voice_cmd); // 入列
}

void inner_voice_who(uint8_t wholevel)
{
	 
	inner_voice_add_cmd(ACCORD_WHO_STAND); // 
		 
    if (wholevel == 0)  // 根据who等级选择增加一条语音
    {
        inner_voice_add_cmd(ON_LOW_SIDE);
    	inner_voice_add_cmd(PLS_REMEASURE_OR_MEDICAL_ATTENT); // 
    }
	else if (wholevel <= 3)
    {
        inner_voice_add_cmd(NORMAL);
    }
    else
    {
        inner_voice_add_cmd(ON_HIGH_SIDE);
    }	
}
void combbine_test(void)
{
    static uint8_t step = 0;
    uint8_t voice_temp = 0; // 取队列数据
    my_dac_open();
    if (step == 0)
    {
        step++;

        // inner_voice_combine_cmd(INNER_VOICE_PRES_UNIT_MMG, SIDE_LEFT,122, 88, 66);
        // inner_voice_who(1);
            Queue_Clear(&qVoice);

        for (uint8_t i = 0; i <= BP_HIGH_SEEK_MEDICAL_ATTENTION_FAST; i++)
        {
            Queue_Push(&qVoice, i); 
        }
        
        /* code */
    }
    else if (step == 1)
    { 
        if (Queue_Count(&qVoice) > 0)
        {
            if (Queue_Pop(&qVoice, &voice_temp) == QUEUE_OK)
            {
                aky_voice_table_play(voice_temp);
                step=2;
                // if (VoiceStop)
                // {
                //     Queue_Clear(&qVoice);
                //     break;
                // }
                
            }
        }
        else
        {
            Queue_Clear(&qVoice);
            step = 0;
        }

    }
    else if (step == 2)
    {
        if (flag_wav_busy == 0)
        {
            step = 1;
            /* code */
        }
 
    }
    
}

//(1) 正在播报 (0)空闲
uint8_t get_voice_busy_stat(void)
{
    return flag_wav_busy;
}
